<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="机构ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orgId">
              <a-input v-model="model.orgId" placeholder="请输入机构ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="机构名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orgName">
              <a-textarea v-model="model.orgName" rows="4" placeholder="请输入机构名称" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="机构英文名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enOrgName">
              <a-input v-model="model.enOrgName" placeholder="请输入机构英文名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="localOrgName" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="localOrgName">
              <a-input v-model="model.localOrgName" placeholder="请输入localOrgName"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="机构简称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orgShortName">
              <a-input v-model="model.orgShortName" placeholder="请输入机构简称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="corporateRepresentative" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="corporateRepresentative">
              <a-input v-model="model.corporateRepresentative" placeholder="请输入corporateRepresentative"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="orgDesc" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orgDesc">
              <a-textarea v-model="model.orgDesc" rows="4" placeholder="请输入orgDesc" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="机构代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orgCode">
              <a-input v-model="model.orgCode" placeholder="请输入机构代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="单位职能" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orgType">
              <a-input v-model="model.orgType" placeholder="请输入单位职能"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="机构级别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orgLevel">
              <a-input v-model="model.orgLevel" placeholder="请输入机构级别"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="行政区名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="canton">
              <a-input v-model="model.canton" placeholder="请输入行政区名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="行政区代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cantonCode">
              <a-input v-model="model.cantonCode" placeholder="请输入行政区代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="address">
              <a-textarea v-model="model.address" rows="4" placeholder="请输入地址" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="homeUrl" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="homeUrl">
              <a-input v-model="model.homeUrl" placeholder="请输入homeUrl"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="authorizedOrgIf" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="authorizedOrgIf">
              <a-input v-model="model.authorizedOrgIf" placeholder="请输入authorizedOrgIf"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否生产单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="forbidIf">
              <a-input v-model="model.forbidIf" placeholder="请输入是否生产单位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="isEmptyOrg" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isEmptyOrg">
              <a-input v-model="model.isEmptyOrg" placeholder="请输入isEmptyOrg"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="启用或停用标识" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentState">
              <a-input v-model="model.currentState" placeholder="请输入启用或停用标识"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="remarks" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remarks">
              <a-textarea v-model="model.remarks" rows="4" placeholder="请输入remarks" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="创建人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createDate">
              <j-date placeholder="请选择创建人" v-model="model.createDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="创建人ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createUserId">
              <a-input v-model="model.createUserId" placeholder="请输入创建人ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="创建人应用ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createAppId">
              <a-input v-model="model.createAppId" placeholder="请输入创建人应用ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="更新日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="updateDate">
              <j-date placeholder="请选择更新日期" v-model="model.updateDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="更新人ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="updateUserId">
              <a-input v-model="model.updateUserId" placeholder="请输入更新人ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审核日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="checkDate">
              <j-date placeholder="请选择审核日期" v-model="model.checkDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审核人ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="checkUserId">
              <a-input v-model="model.checkUserId" placeholder="请输入审核人ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="mdmCode" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mdmCode">
              <a-input v-model="model.mdmCode" placeholder="请输入mdmCode"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="cantonDesc" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cantonDesc">
              <a-textarea v-model="model.cantonDesc" rows="4" placeholder="请输入cantonDesc" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="companyId" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="companyId">
              <a-input v-model="model.companyId" placeholder="请输入companyId"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="customerDivision" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerDivision">
              <a-input v-model="model.customerDivision" placeholder="请输入customerDivision"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="customerGroup" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerGroup">
              <a-input v-model="model.customerGroup" placeholder="请输入customerGroup"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="customerTelephone" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerTelephone">
              <a-input v-model="model.customerTelephone" placeholder="请输入customerTelephone"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="reportingStandard" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reportingStandard">
              <a-input-number v-model="model.reportingStandard" placeholder="请输入reportingStandard" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="reportingTime" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reportingTime">
              <j-date placeholder="请选择reportingTime" v-model="model.reportingTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="attachmentJournalId" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="attachmentJournalId">
              <a-input v-model="model.attachmentJournalId" placeholder="请输入attachmentJournalId"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="mustVerifyFlag" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mustVerifyFlag">
              <a-input v-model="model.mustVerifyFlag" placeholder="请输入mustVerifyFlag"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="oilField" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="oilField">
              <a-input v-model="model.oilField" placeholder="请输入oilField"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="bsflag" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bsflag">
              <a-input v-model="model.bsflag" placeholder="请输入bsflag"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="sendIndicate" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sendIndicate">
              <a-input v-model="model.sendIndicate" placeholder="请输入sendIndicate"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="createOrgId" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createOrgId">
              <a-input v-model="model.createOrgId" placeholder="请输入createOrgId"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="updateOrgId" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="updateOrgId">
              <a-input v-model="model.updateOrgId" placeholder="请输入updateOrgId"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="orgFunction" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orgFunction">
              <a-input v-model="model.orgFunction" placeholder="请输入orgFunction"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="orgAdmLevel" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orgAdmLevel">
              <a-input v-model="model.orgAdmLevel" placeholder="请输入orgAdmLevel"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="source" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="source">
              <a-input v-model="model.source" placeholder="请输入source"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="删除标志，1-删除，0或空未删除" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deleFlag">
              <a-input v-model="model.deleFlag" placeholder="请输入删除标志，1-删除，0或空未删除"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="父级组织机构ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orgParentId">
              <a-input v-model="model.orgParentId" placeholder="请输入父级组织机构ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审批意见" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="checkOpinion">
              <a-textarea v-model="model.checkOpinion" rows="4" placeholder="请输入审批意见" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="注册审批状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="checkState">
              <a-input v-model="model.checkState" placeholder="请输入注册审批状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="排序号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sorder">
              <a-input-number v-model="model.sorder" placeholder="请输入排序号" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="业务编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessCode">
              <a-input v-model="model.businessCode" placeholder="请输入业务编码"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'CdOrganizationForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           orgId: [
              { required: true, message: '请输入机构ID!'},
           ],
        },
        url: {
          add: "/cdOrganization/cdOrganization/add",
          edit: "/cdOrganization/cdOrganization/edit",
          queryById: "/cdOrganization/cdOrganization/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>